package com.mission.schedule.CommonDialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.StyleRes;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;

import com.mission.schedule.R;
import com.mission.schedule.applcation.App;
import com.mission.schedule.bean.TagCommandBean;
import com.mission.schedule.utils.DateUtil;
import com.mission.schedule.utils.SharedPrefUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * 月视图对话框
 * Created by liwei on 2017/4/18.
 */

public class MonthViewDialog extends Dialog {

    CallBack callBack;

    SharedPrefUtil sharedPrefUtil = null;
    Context context;
    WindowManager windowManager;

    List<TagCommandBean> list = new ArrayList<TagCommandBean>();

    App app = App.getDBcApplication();


    public MonthViewDialog(@NonNull final Context context, @StyleRes int themeResId, WindowManager windowManager, final String date) {
        super(context, themeResId);
        this.context = context;
        this.windowManager = windowManager;


        setCanceledOnTouchOutside(true);

        View view = LayoutInflater.from(context).inflate(R.layout.monthviewdialog, null);
        setContentView(view);

        TextView title = view.findViewById(R.id.title);
        ImageView close = view.findViewById(R.id.close);
        int day_c = DateUtil.days(date);
        String day = "";
        if (day_c == 0) {
            day = "今天";
        }
        if (day_c == 1) {
            day = "明天";
        }
        if (day_c == 2) {
            day = "后天";
        }
        if (day_c == -1) {
            day = "昨天";
        }
        if (day_c == -2) {
            day = "前天";
        }
        if (day_c > 2) {
            day = day_c+"天后";
        }
        if (day_c < -2) {
            day = day_c+"天前";
        }
        title.setText(date.substring(5, date.length()) + " " + DateUtil.Week(date) + " " + day);

        close.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Window window = getWindow();
        window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN | WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
        WindowManager.LayoutParams params = window.getAttributes();
        window.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL);
        params.width = ViewGroup.LayoutParams.MATCH_PARENT;
        params.height = ViewGroup.LayoutParams.MATCH_PARENT;
        window.setAttributes(params);

    }

    public interface CallBack {
        void reminderEditTime(String name, String id);
    }

    public CallBack getCallBack() {
        return callBack;
    }

    public void setCallBack(CallBack callBack) {
        this.callBack = callBack;
    }

}
